package com.myproject.thread.lock;

public class Test2 {

    public static volatile Person p = null;
    public static void main(String[] args) {
        Boy boy = new Boy();
        Girl girl = new Girl();
        System.out.println(boy.getGender());
        System.out.println(girl.getGender());
        new Thread(()->{
            p=boy;
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread()+" "+p.getGender());
        }).start();

        new Thread(()->{
            p=girl;
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread()+" "+p.getGender());
        }).start();

    }
}
